﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using CommonUtils;
using MyTextImport = System.Lazy<CommonUtils.ITextImport, CommonUtils.ITextImportMetaData>;

namespace TextExtractors
{
    [Export("TextExtractor",typeof(ITextImportController))]
    //[ExportMetadata("TestData", 25L)]
    public class ExportProviderController : ITextImportController
    {
#pragma warning disable 649
        [ImportMany(typeof(ITextImport))]
        IEnumerable<MyTextImport> _providers;
#pragma warning restore 649
        //IFileReader[] _textProviders;
        public ExportProviderController()
        {
            //_textProviders = new IFileReader[] { new DocReader(), new PDFParser(), new RtfFileReader(), new HtmlFileReader(), new TxtFileReader() };
        }
        public IEnumerable<MyTextImport> TextProviders
        {
            get { return _providers; }
        }
        public MyTextImport this[string extension]
        {
            get
            {
                try
                {
                    return _providers.First((MyTextImport fr)=> { return fr.Metadata.FileExtension.IndexOf(extension, StringComparison.OrdinalIgnoreCase) >= 0; });
                    //return _textProviders.First(delegate(IFileReader fr) { return fr.FileExtension.IndexOf(extension, StringComparison.OrdinalIgnoreCase) >= 0; });
                }
                catch
                {

                    return null;
                }
            }
        }
    }
  /*  public class ProgressEventArgs : EventArgs
    {
        public string Description;
        public float Progress;
    }
*/
}
